# -*- coding: utf-8 -*-
# flake8: noqa
import base64
import pickle
import struct

from qiniu import Auth, put_file, etag, put_stream, put_data

# 需要填写你的 Access Key 和 Secret Key
access_key = 'x0abHv3YMHSK_Gii2KM9CVPIC25EYg__LrkBId5c'
secret_key = 'oNXf-Ibo7E341Zz2QXfWBrlZP0BVTV-Z86fxcqGE'
# 构建鉴权对象
q = Auth(access_key, secret_key)
# 要上传的空间
bucket_name = 'lixianhe-cdn'
# 上传后保存的文件名
key = 'qiniu-test-demo2.jpg'
# 生成上传 Token，可以指定过期时间等
token = q.upload_token(bucket_name, key, 3600)
print(token)
# 要上传文件的本地路径
localfile = '/Users/lixianhe/Downloads/lixianhe1.jpg'

# 获取二进制流
with open(localfile, mode="rb+") as zip_file:
     contents = zip_file.read()

ret, info = put_data(token,key, contents)
print(info)